<?php
class App_Model extends CI_Model{
	public function __construct(){
		parent::__construct();
		$this->db 		= $this->load->database('default', TRUE);
	}
	public function saveNews($ref = null){
		if ($this->checkExistNews($ref)){
			return false;
		}
		$this->db->insert('news', $ref);
		return $this->db->affected_rows();
	}
	private function checkExistNews($ref =null){
		$this->db->select('app_id');
//		$this->db->where(array('app_delete_flag'=>0,'app_title'=>$ref['app_title'],'app_pubdate'=>$ref['app_pubdate'],'app_link'=>$ref['app_link']));
		$this->db->where(array('app_delete_flag'=>0,'app_title'=>$ref['app_title'],'app_link'=>$ref['app_link']));
		$data = $this->db->get('news');
		return $data->num_rows();
	}
	public function getNewsByDay($day=null){
		$this->db->select('app_id,app_title, app_description,app_img');
		$this->db->where(array('app_delete_flag'=>0,'app_update'=>$day));
		$data = $this->db->get('news')->result_array();
		return $data;
	}
	public function getDetail($id){
		$this->db->select('app_details,app_description,app_title');
		$this->db->where(array('app_delete_flag'=>0,'app_id'=>$id));
		$data = $this->db->get('news')->result_array();
		return $data;
	}
}